package com.ubst.smartad.impl;

import java.sql.*;
import java.util.*;
import java.io.*;

import com.ubst.smartad.dao.TestDO;
import com.ubst.smartad.common.TimeUtil;
import com.ubst.smartad.logger.Debug;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

public class TestMngImpl {
	
	Connection con = null;
	private String serverName;
	private Debug debug;
	//private FileHostEnv fhostEnv;


    /** 
     * 생성자
     *   
     *   
    */ 
	public TestMngImpl(Connection con, String serverName, String log_level) {
		this.con = con;
		this.serverName = serverName;
		this.debug = new Debug("TestMngImpl", log_level);
		//this.fhostEnv = FileHostEnv.getInstance(serverName);

	}

	
	/**
	 *  @author Kswany
	 * 	Test jqGrid List 가져오기
	 * 
	 *  searchStr: 검색조건
	 *  orderBy: sort조건
	 *  prev_page: first limit 
	 *  next_page: last limit
	 *  
	 * **/
	public List<TestDO> getBoardList(String searchStr, String orderBy, int prev_page, int next_page) 
//			throws SQLException{
			throws Exception{
		PreparedStatement pstmt=null;
		ResultSet rs = null;
		Vector v_log = new Vector();
		TestDO test_data_info = null;
		List<TestDO> test_datas = null;
		try{
//			StringBuffer qrybuf = new StringBuffer();
//			qrybuf.append("SELECT")
//					.append("  A.LOG_SERIAL LOG_SERIAL, A.USER_ID USER_ID, A.ORG_CODE ORG_CODE ")
//					.append("  ,A.FILE_NAME FILE_NAME, A.FILE_SIZE FILE_SIZE, A.USER_IP USER_IP ")
//					.append("  ,A.LOG_TYPE LOG_TYPE, A.FDIR_NAME FDIR_NAME, A.LOG_DATE LOG_DATE ")
//					.append(" FROM JX_DRIVE_LOG A")
//					.append(" ORDER BY LOG_DATE DESC LIMIT ?,?");
//
//			int startCount = (pageNum-1)*list_cnt;
//			pstmt = con.prepareStatement(qrybuf.toString());
//			//pstmt.setString(1, serverName);
//			pstmt.setInt(1, startCount);
//			pstmt.setInt(2, list_cnt);
//			debug.debug("<!> getLogList Query ==> "+qrybuf.toString());
//
//		rs=pstmt.executeQuery();
//		while(rs.next()){
//			log_data_info=new LogDataDO();
//			log_data_info.log_serial = rs.getInt("LOG_SERIAL");
//			log_data_info.domain = serverName;
//			log_data_info.user_id = rs.getString("USER_ID");
//			log_data_info.org_code = rs.getString("ORG_CODE");
//			log_data_info.file_name = rs.getString("FILE_NAME");
//			log_data_info.file_size = rs.getDouble("FILE_SIZE");
//			log_data_info.user_ip = rs.getString("USER_IP");
//			log_data_info.log_type = rs.getString("LOG_TYPE");
//			log_data_info.fdir_name = rs.getString("FDIR_NAME");
//			log_data_info.log_date = rs.getString("LOG_DATE");
//			
//			v_log.add(log_data_info);
//			log_data_info = null;
//		}
//		rs.close();
//		pstmt.close();
			
			
		/*
		 *  DB value 값세팅 구현 로직 들어갈 부분
		 */
		// 가상데이터
		test_data_info = new TestDO();
		test_data_info.board_no = 1;
		test_data_info.user_id = "TEST01";
		test_data_info.title = "첫번째글입니다";
		test_data_info.write_date = "2013-07-25";
		test_data_info.hit_count = 1;
		v_log.add(test_data_info);
		
		test_data_info = new TestDO();
		test_data_info.board_no = 2;
		test_data_info.user_id = "TEST02";
		test_data_info.title = "두번째글입니다";
		test_data_info.write_date = "2013-07-26";
		test_data_info.hit_count = 7;
		v_log.add(test_data_info);
		
		test_data_info = new TestDO();
		test_data_info.board_no = 3;
		test_data_info.user_id = "TEST01";
		test_data_info.title = "세번째글입니다";
		test_data_info.write_date = "2013-07-27";
		test_data_info.hit_count = 3;
		v_log.add(test_data_info);
		
		test_data_info = new TestDO();
		test_data_info.board_no = 4;
		test_data_info.user_id = "TEST01";
		test_data_info.title = "네번째글입니다";
		test_data_info.write_date = "2013-07-27";
		test_data_info.hit_count = 3;
		v_log.add(test_data_info);
		
		test_data_info = new TestDO();
		test_data_info.board_no = 5;
		test_data_info.user_id = "TEST01";
		test_data_info.title = "다섯번째글입니다";
		test_data_info.write_date = "2013-07-27";
		test_data_info.hit_count = 7;
		v_log.add(test_data_info);
		
		test_data_info = new TestDO();
		test_data_info.board_no = 6;
		test_data_info.user_id = "TEST01";
		test_data_info.title = "여섯번째글입니다";
		test_data_info.write_date = "2013-07-27";
		test_data_info.hit_count = 1;
		v_log.add(test_data_info);
		
		test_data_info = new TestDO();
		test_data_info.board_no = 7;
		test_data_info.user_id = "TEST01";
		test_data_info.title = "일곱번째글입니다";
		test_data_info.write_date = "2013-07-27";
		test_data_info.hit_count = 2;
		v_log.add(test_data_info);
		
		test_data_info = new TestDO();
		test_data_info.board_no = 8;
		test_data_info.user_id = "TEST01";
		test_data_info.title = "세번째글입니다";
		test_data_info.write_date = "2013-07-22";
		test_data_info.hit_count = 3;
		v_log.add(test_data_info);
		
		test_data_info = new TestDO();
		test_data_info.board_no = 9;
		test_data_info.user_id = "TEST01";
		test_data_info.title = "ㅅㄷㄴㅅ1다";
		test_data_info.write_date = "2013-07-01";
		test_data_info.hit_count = 3;
		v_log.add(test_data_info);
		
		test_data_info = new TestDO();
		test_data_info.board_no = 10;
		test_data_info.user_id = "TEST01";
		test_data_info.title = "test1234";
		test_data_info.write_date = "2013-04-22";
		test_data_info.hit_count = 88;
		v_log.add(test_data_info);
		
		test_data_info = new TestDO();
		test_data_info.board_no = 11;
		test_data_info.user_id = "TEST01";
		test_data_info.title = "마지막째글입니다";
		test_data_info.write_date = "2013-07-21";
		test_data_info.hit_count = 3;
		v_log.add(test_data_info);
		//////
		
		int log_cnt = v_log.size();
		if(log_cnt>0){
			test_datas = new ArrayList(); 
			for(int i=0;i<log_cnt;i++){
				test_datas.add(i, (TestDO)v_log.elementAt(i));

			}
		}
//	}catch (SQLException e){
	}catch (Exception e){
		throw e;
	}finally{
//		if ( rs != null) try{rs.close();}catch(SQLException ee){}
//		if ( pstmt != null) try{pstmt.close();}catch(SQLException ee){}
	}

	return test_datas;
}
	
}
